// DBConnectionManager.h: interface for the DBConnectionManager class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_DBCONNECTIONMANAGER_H__0D334EE8_6D8A_43AE_AAC3_CC0393C7EF52__INCLUDED_)
#define AFX_DBCONNECTIONMANAGER_H__0D334EE8_6D8A_43AE_AAC3_CC0393C7EF52__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <afxtempl.h>

namespace DAWrapper
{

class AFX_EXT_CLASS DBConnectionManager  
{
public:
	static DBConnectionManager* Instance();
	static void DeleteInstance();

private:
	DBConnectionManager();
	~DBConnectionManager();
	static DBConnectionManager* g_Instance;

public:
	_ConnectionPtr* GetConnectionPtrByUri( const CString& uri );

private:
	_ConnectionPtr* AddConnectionPtrByUriFlush( const CString& uri );

private:
	class Uri2Connection
	{
	public:
		Uri2Connection( const CString& uri ) : m_uri( uri ) { m_connPtr = new _ConnectionPtr( __uuidof( Connection ) ); }
		~Uri2Connection() { 
			if ( m_connPtr ) {
				if ( (*m_connPtr)->GetState() == adStateOpen ) (*m_connPtr)->Close();
				delete m_connPtr;
			} 
		}

	public:
		const CString& Uri() const { return m_uri; }
		_ConnectionPtr* ConnectionPtr() const { return m_connPtr; }
//		void Uri( const CString& uri ) { m_uri = uri; }
		void ConnectionPtr( _ConnectionPtr* ptr ) { m_connPtr = ptr; }

	private:
		CString m_uri;
		_ConnectionPtr* m_connPtr;
	};

private:
	CArray<Uri2Connection*,Uri2Connection*> m_Connections;
};

}

#endif // !defined(AFX_DBCONNECTIONMANAGER_H__0D334EE8_6D8A_43AE_AAC3_CC0393C7EF52__INCLUDED_)
